package designpattern.struct.proxy.dynamic;

import designpattern.struct.proxy.dynamic.cglibs.CGlibProxyFactory;
import designpattern.struct.proxy.dynamic.cglibs.Fly;
import designpattern.struct.proxy.dynamic.jdks.DynamicHandler;
import designpattern.struct.proxy.dynamic.jdks.Eat;
import designpattern.struct.proxy.dynamic.jdks.EatApple;
import designpattern.struct.proxy.dynamic.jdks.JDKProxyFactory;

import java.lang.reflect.Proxy;

/**
 * 测试类
 *
 * @author cuihao
 * @date 2018/3/1
 */
public class Test {

    public static void main(String[] args) {
        // JDK代理 返回一个代理类

        EatApple eatApple = new EatApple();
        Eat eat = (Eat) Proxy.newProxyInstance(eatApple.getClass().getClassLoader(), eatApple.getClass().getInterfaces(), new DynamicHandler(eatApple));
        eat = (Eat) JDKProxyFactory.getProxy(eatApple);
        eat.eat();

        // CGlib代理
        Fly fly = (Fly) CGlibProxyFactory.getProxy(Fly.class);
        fly.fly();

    }
}